package Classes;



import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class teList extends JPanel  implements ListSelectionListener 
{
	
	private DefaultListModel listModel;
    private JList list;
    private String lstName;
    private JScrollPane listScrollPane;
    private String selectedItem;
	
	public teList(int x, int y) 
	{
		super();//new BorderLayout() 
		
		listModel = new DefaultListModel();
		setList(new JList(listModel));
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		list.setSelectedIndex(0);
		list.setPreferredSize(new java.awt.Dimension(x,y));
	    listScrollPane = new JScrollPane(list);
		add(listScrollPane,BorderLayout.CENTER);
	}
	
    public void addElement(String[] lst)
    {
    	for(String el:lst)
    	{
    		listModel.addElement(el);
    	}    	
    }
	
 
   
   public void setListBorder()
   {
	    JPanel listPanel = new JPanel();
		listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.LINE_AXIS));
		listPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
		
	    JPanel listContainer = new JPanel(new GridLayout(1,1));	    
	    listContainer.setBorder(BorderFactory.createTitledBorder(getLstName()));
	    listContainer.add(listScrollPane);
	    listPanel.add(listContainer);
	    this.add(listPanel);//,BorderLayout.CENTER
   }

public String getLstName() {
	return lstName;
}

public void setLstName(String lstName) {
	this.lstName = lstName;
}

public DefaultListModel getListModel() {
	return listModel;
}

public void setListModel(DefaultListModel listModel) {
	this.listModel = listModel;
}

public JList getList() {
	return list;
}

public void setList(JList list) {
	this.list = list;
}

@Override
public void valueChanged(ListSelectionEvent arg0)
{
	if (arg0.getValueIsAdjusting() == false)
	{
	   System.out.println("valueChanged, event=" + arg0);
	   
	   setSelectedItem((String)list.getSelectedValue());
	
	}
	
}

public String getSelectedItem() {
	return selectedItem;
}

public void setSelectedItem(String selectedItem) {
	this.selectedItem = selectedItem;
}

}
